`
https://leetcode.cn/problems/count-subarrays-with-score-less-than-k/
`

/**
 * @param {number[]} nums
 * @param {number} k
 * @return {number}
 */
var countSubarrays = function (nums, k) {
  const n = nums.length
  let sum = 0
  let res = 0
  let left = 0, right = 0

  while (right < n) {
    const n1 = nums[right++]
    sum += n1

    while (sum * (right - left) >= k) {
      const n2 = nums[left++]
      sum -= n2
    }

    res += right - left
  }

  return res
};